/**
 * 防抖
 * @param fun
 * @param delay
 * @returns {(function(...[*]=): void)|*}
 * @private
 */
export function __debounce(fun, delay = 200) {
    let timer;
    return function (...args) {
        if (timer) clearTimeout(timer);
        timer = setTimeout(() => fun.apply(this, args), delay);
    };
}

/**
 * 节流
 * @param fun
 * @param interval
 * @returns {(function(...[*]=): void)|*}
 * @private
 */
export function __throttle(fun, interval = 200) {
    let last;
    let timer;
    return function (...args) {
        let now = +new Date();
        if (last && now - last < interval) {
            clearTimeout(timer);
            timer = setTimeout(() => {
                last = now;
                fun.apply(this, args);
            })
        } else {
            last = now;
            fun.apply(this, args);
        }
    };
}